package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.domain.TInstitutionPersonDevice;
import com.ruoyi.system.domain.TPerson;
import com.ruoyi.system.dto.req.PersonReqDto;
import com.ruoyi.system.dto.resq.DeviceRespDto;
import com.ruoyi.system.dto.resq.PersonRespDto;
import com.ruoyi.system.mapper.TDeviceMapper;
import com.ruoyi.system.mapper.TInstitutionPersonDeviceMapper;
import com.ruoyi.system.service.TPersonService;
import com.ruoyi.system.mapper.TPersonMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author dell
* @description 针对表【t_person(个人用户信息表)】的数据库操作Service实现
* @createDate 2023-11-16 17:52:52
*/
@Service
public class TPersonServiceImpl extends ServiceImpl<TPersonMapper, TPerson>
    implements TPersonService{

    @Autowired
    private TPersonMapper tPersonMapper;

    @Autowired
    private TInstitutionPersonDeviceMapper tInstitutionPersonDeviceMapper;

    @Autowired
    private TDeviceMapper tDeviceMapper;

    @Override
    public List<PersonRespDto> selectPersonList(PersonReqDto personReqDto) {

        return tPersonMapper.selectPersonList(personReqDto);
    }

    @Override
    public PersonRespDto selectOneByPersonId(String personId) {

        return tPersonMapper.selectOneByPersonId(personId);
    }

    @Override
    public List<DeviceRespDto> getDeviceListByPersonId(String personId) {

//        List<TInstitutionPersonDevice> tInstitutionPersonDevices = tInstitutionPersonDeviceMapper.selectList(new LambdaQueryWrapper<TInstitutionPersonDevice>().eq(TInstitutionPersonDevice::getOwnerId, personId));
//
//        List<DeviceRespDto> list = new ArrayList<>();
//
//        for (TInstitutionPersonDevice tInstitutionPersonDevice : tInstitutionPersonDevices) {
//            DeviceRespDto deviceRespDto = tDeviceMapper.selectOneByDeviceId(tInstitutionPersonDevice.getDeviceId());
//            list.add(deviceRespDto);
//        }

        return tDeviceMapper.selectListByOwnerId(personId);
    }
}




